package com.rui.shiliao.entity;

import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import android.util.Log;

public class EatWorldHandler extends DefaultHandler {
    private int addDateCount = 0;
    private boolean addDateState = false;
    private String dirname = null;
    private EatWorld loseWeight;
    private boolean setDateState = false;
    private boolean startRead = false;
    private String tagName = null;
    private List<EatWorld> worlds;

    public EatWorldHandler(List<EatWorld> paramList, String paramString) {
        this.worlds = paramList;
        this.dirname = paramString;
    }

    public void characters(char[] paramArrayOfChar, int paramInt1, int paramInt2) throws SAXException {
        if (this.dirname.equals("name")) {
            this.worlds.add(this.loseWeight);
        }
        return;
    }

    public void endDocument() throws SAXException {
    }

    public void endElement(String paramString1, String paramString2, String paramString3) throws SAXException {
        if (this.addDateState)
            this.addDateCount = (-1 + this.addDateCount);
        Log.i("eat", "endElement -> addDateCount : " + this.addDateCount);
        if ((this.addDateCount == 2) && (paramString2.equals("resource"))) {
            this.setDateState = false;
            this.worlds.add(this.loseWeight);
        }
        if (this.addDateCount == 0) {
            Log.i("eat", "endElement -> addDateCount2 : " + this.addDateCount);
            this.startRead = false;
            this.setDateState = false;
            this.tagName = "";
            endDocument();
        }
    }

    public void startDocument() throws SAXException {
    }

    public void startElement(String paramString1, String paramString2, String paramString3, Attributes paramAttributes) throws SAXException {
        this.tagName = paramString2;
        if (paramAttributes.getValue("name").equals(this.dirname)) {
            this.addDateCount = 0;
            this.startRead = true;
            this.addDateState = true;
        }
        Log.i("eat", "startElement -> attributes.getValue(\"name\") -> " + paramAttributes.getValue("name"));
        if (this.startRead) {
            if (this.addDateState)
                this.addDateCount = (1 + this.addDateCount);
            Log.i("eat", "startElement -> addDateCount : " + this.addDateCount);
            if ((this.addDateCount == 2) && (!this.setDateState)) {
                this.loseWeight = new EatWorld();
                this.loseWeight.setFile(paramAttributes.getValue("file"));
                this.loseWeight.setName(paramAttributes.getValue("name"));
                this.loseWeight.setTagname(paramAttributes.getValue("tagname"));
                this.loseWeight.setType(paramAttributes.getValue("type"));
                Log.i("eat", "startElement -> eatword -> " + this.loseWeight);
                this.setDateState = true;
            }
        }
    }
}